package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.OrderSetting;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

public interface OrderSettingMapper extends BaseMapper<OrderSetting> {
    @Select("select id from t_ordersetting where ORDERDATE = #{orderDate}")
    OrderSetting findOrderSettingByOrderDate(@Param("orderDate") Date orderDate);

    @Select("select ORDERDATE,number,RESERVATIONS from t_ordersetting where orderdate between #{beginDate} and #{endDate}")
    List<OrderSetting> findSettingListByDate(@Param("beginDate") String beginDate, @Param("endDate") String endDate);

    @Update("update t_ordersetting set number = #{number} where orderdate = #{orderdate}")
    void updateNumberByOrderDate(@Param("number") int number, @Param("orderdate") String orderdate);

    @Select("select count(1) from t_ordersetting where ORDERDATE = #{orderdate} and number>RESERVATIONS")
    int isOrderOkByOrderDate(@Param("orderdate") String orderdate);

    @Update("update t_ordersetting set RESERVATIONS = RESERVATIONS+1 where ORDERDATE=#{orderdate}")
    void updateReservationsByOrderDate(@Param("orderdate") String orderdate);
}
